<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="/res/third/bootstrap3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="/res/common/js/jquery.1.9.1.min.js" type="text/javascript"></script>
<script src="/res/third/artDialog/jquery.artDialog.js" type="text/javascript"></script>
<script src="/res/third/validate/jquery.validate.js" type="text/javascript"></script>
<script src="/res/third/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
<script type="text/javascript">
	function sosuo(){
		var lpath =location.pathname;
		var pageNo = $("#pageNo").val();
		$("#soform").attr("action",lpath+"?pageNo="+pageNo);
		$("#soform").submit();
	}
	
	
	
	var fulldialog;
	function fullscreen(id,quoteId){
		top.addTempTab("/enq/v_quote_item.do?so_enquiryid="+id+"&so_quoteid="+quoteId);
	}
	
	function changestatrecallback(){
		refresh();
	}
	
	
	var exceldialog=null;
	function uploaddialog(enquiryid,title,qtype){
		var param ={id:enquiryid,title:title,qtype:qtype};
		exceldialog = art.dialog.uploadFile("上传excel",{callback:"uploadcallback",params:JSON.stringify(param),userpath:"admin",extensions:"xls,xlsx"});
	}
	
	function uploadcallback(response,params){
		exceldialog.close();
		art.dialog.post({
			url:"/enq/o_excel_quote_update.do",
			data:{url:response.url,id:params.id},
			success:function(data){
				if(data.success){//更新成功
					art.dialog.tips("上传成功,转入分析");
					setTimeout(function(){
						if(params.qtype==1){
                            analysis(params.id,params.title);//分析excel
						}else{

						}
						refresh();
					},100)
				}else{
					alert(data.msg);
				}			
			}
		},"更新地址");
	}
	

	/* 审核通过 */
// 	改变状态的提示页面
//	function changeState(enquiryid ,prostate){
//		art.dialog.load("请做出选择","/enq/v_prostate_change.do",{enquiryid:enquiryid,prostate:prostate});
//	}

	function purAnalysis(excelPath , excelName , quoteId , projectId , enquiryId){
		$.ajax({
			url : '/enq/o_anaylsis_quote.do' ,
			type : 'post' ,
			dataType : 'json',
			data :{
				excelPath : excelPath,
				excelName : excelName,
				quoteId : quoteId ,
				projectId : projectId ,
				enquiryId : enquiryId
			},
			beforeSend:function () {
				$.messager.progress({
					text : "分析中",
					interval : 100
				});
			},
			success : function(data){
				$.messager.progress('close');
				if(data.success){
					$("#anaTable tbody").empty();
					$.each(data.attributes.items , function(i , item){
						$("#anaTable tbody").append("<tr>");
						$("#anaTable tbody").append("<td>"+(i+1)+"<input type='hidden' name='items["+i+"].enquiryItemId' value='"+item.enquiryItemId+"' /><input type='hidden' name='items["+i+"].quoteId' value='"+item.quoteId+"' /><input type='hidden' name='items["+i+"].categorySId' value='"+item.categorySId+"' /><input type='hidden' name='items["+i+"].enquiryId' value='"+data.attributes.enquiryId+"' /><input type='hidden' name='items["+i+"].projectId' value='"+data.attributes.projectId+"' /></td>");
						$("#anaTable tbody").append("<td>"+item.productName+"<input type='hidden' name='items["+i+"].productName' value='"+item.productName+"' /></td>");
						$("#anaTable tbody").append("<td>"+item.brand+"<input type='hidden' name='items["+i+"].brand' value='"+item.brand+"' /></td>");
						$("#anaTable tbody").append("<td>"+item.model+"<input type='hidden' name='items["+i+"].model' value='"+item.model+"' /></td>");
						$("#anaTable tbody").append("<td>"+item.unit+"<input type='hidden' name='items["+i+"].unit' value='"+item.unit+"' /></td>");
						$("#anaTable tbody").append("<td>"+item.quantity+"<input type='hidden' name='items["+i+"].quantity' value='"+item.quantity+"' /></td>");
						$("#anaTable tbody").append("<td>"+item.unitprice+"<input type='hidden' name='items["+i+"].unitprice' value='"+item.unitprice+"' /></td>");
						$("#anaTable tbody").append("<td>"+item.totalPrice+"<input type='hidden' name='items["+i+"].totalPrice' value='"+item.totalPrice+"' /></td>");
						$("#anaTable tbody").append("<td>"+item.descr+"<input type='hidden' name='items["+i+"].descr' value='"+item.descr+"' /></td>");
						$("#anaTable tbody").append("</tr>");
					});

					art.dialog({
						title: "采购询价报价分析结果",
						content: $("#analysisList").html(),
						height: 200,
						button: [
							{
								name: '确认分析',
								callback: function () {
									$("#quoteId").val(quoteId);
									$.ajax({
										url : '/enq/o_post_quote.do',
										type : 'post' ,
										dataType : 'json' ,
										data : $("#listForm").serialize(),
										success : function(data){
											if(data.success){
												alert("已分析成功！");
												location.reload();
											}else{
												alert(data.msg);
												location.reload();
											}
										}
									});
									return false;
								},
								focus: true
							}
						]
					});

//					alert("分析成功！");
				}else{
					alert(data.msg);
				}
			}
		});
	}



    /* 分析excel */
    function analysis(id,title){
        top.addTempTab("/enq/o_retry.do?id="+id+"&autodelete=1&type=2");
    }

    function changeState(quoteId , state){
    	if(quoteId){
    		if(state == 1){
				artDialog.confirm("是否确定通过审核？" , function(){
					$.ajax({
						url : '/enq/o_quote_change_state.do' ,
						type : 'post' ,
						dataType : 'json' ,
						data : {quoteId : quoteId , state : state},
						success : function (data) {
							if(data.success){
								alert("通过审核成功！");
								location.reload();
							}else{
								alert(data.msg);
	//							location.reload();
							}
						}
					});
				});
			}else if(state == 3){
				artDialog.prompt("请输入修改意见" , function (value , $this , $here) {
					if(value == ''){
						artDialog.alert("请输入意见");
						return false;
					}

					$.ajax({
						url : '/enq/o_quote_change_state.do' ,
						type : 'post' ,
						dataType : 'json' ,
						data : {quoteId : quoteId , state : state , suggest:value},
						success : function (data) {
							if(data.success){
								alert("退回修改成功！");
								location.reload();
							}else{
								alert(data.msg);
								//							location.reload();
							}
						}
					});
				});
			}
		}
	}
</script>

<style>
	/*#analysisList {max-height: 450px;overflow: auto}*/
	#anaTable {min-width: 100px;}
	#anaTable td{text-align: center}
	.aui_content{max-height: 400px;overflow: auto;}
</style>
</head>

<body>
	<div style="display: none;" id="analysisList">
		<form id="listForm">
			<input type="hidden" name="quoteId"   id="quoteId"/>
		<table class="table table-hover table-bordered table-striped table-condensed" id="anaTable">
			<thead>
			<tr>
				<th>序号</th>
				<th>设备名称</th>
				<th>品牌</th>
				<th>型号</th>
				<th>单位</th>
				<th>数量</th>
				<th>单价</th>
				<th>小计</th>
				<th>技术参数</th>
			</tr>
			</thead>
			<tbody>

			</tbody>
		</table>
		</form>
	</div>
	<div class="panel panel-info panel-content" style="overflow: auto;">
		<div class="panel-heading">
		<form  id="soform" method="post"  >
		<table >
			<tr>
				<td class="w120 ">
					<select class="form-control"  id="so_project_stat" name="so_project_stat"  >
						<option   value="-1"  >项目状态</option>
						[#list allstats?keys as key ]
							<option value="${key}"  [#if so_project_stat?? && so_project_stat==key ] selected="selected"  [/#if]  >${allstats[key]}</option>
						[/#list]
					</select>
				</td>
				<td class="w120 ">
					<select class="form-control"  id="so_enquiry_type" name="so_enquiry_type"  >
						<option   value="-1"  >询价类型</option>
						[#list allEnquiryType?keys as key ]
							<option value="${key}"  [#if so_enquiry_type?? && so_enquiry_type==key ] selected="selected"  [/#if]  >${allEnquiryType[key]}</option>
						[/#list]
					</select>
				</td>
				<td class="w120 ">
					<select class="form-control"  id="so_enq_stat" name="so_enq_stat"  >
						<option   value="-1"  >报价状态</option>
						[#list allQuoteStat?keys as key ]
							<option value="${key}"  [#if so_enq_stat?? && so_enq_stat==key ] selected="selected"  [/#if]    >${allQuoteStat[key]}</option>
						[/#list]
					</select>
				</td>
				
				<td>
					<div class="input-group">
						<input type="text" class="form-control"  name="so_project_info"  value='${so_project_info!}' placeholder="项目名"> 
						<span class="input-group-btn">
							<button class="btn btn-default" type="button" onclick="sosuo()">多条件搜索</button>
						</span>
					</div>
				</td>
			</tr>
		</table>
		</form>
		</div>
		<table class="table table-hover table-bordered table-striped table-condensed">
			<thead>
				<tr>
					<th>序号</th>
					<th>项目名称</th>
					<th>询价名称</th>
					<th>询价类型</th>
					<th>报价商家</th>
					<th>联系信息</th>
					<th>项目状态</th>
					<th>审核状态</th>
					<th width="7%">报价时间</th>
					<th>excel</th>
					<th>操作</th>
				</tr>
			</thead>
			[#list pagination.list as enquiry ]
			<tr>
				<td>${pagination.pageSize * (pagination.pageNo-1)+enquiry_index+1}</td>
				<td>${enquiry.projectName!}</td>
				<td>${enquiry.enquiryName!}</td>
				<td>[#if enquiry.qtype??]${(enquiry.qtype = 1)?string('预算询价' , '采购询价')}[/#if]</td>
				<td>${enquiry.companyName!}</td>
				<td>${enquiry.realName!}/[#if enquiry.mobile?? ]${enquiry.mobile}[#else]${enquiry.email!}[/#if]</td>
				<td>[#if enquiry.projectState??]${allstats[enquiry.projectState?string]!}[/#if]</td>
				<td>[#if !enquiry.suggest?? || enquiry.suggest == '']${allQuoteStat[enquiry.state?string]!}[#else]<label style="color: red;">退回修改</label>[/#if]</td>
				<td>[#if enquiry.quoteDate??]${enquiry.quoteDate?datetime}[/#if]</td>
				<td style="/*max-width: 75px;*/" >
				    [#if enquiry.excelpath?? && enquiry.excelpath!="" ]
					<a target="_blank" href="${enquiry.excelpath}">有<span class="glyphicon glyphicon-download-alt" aria-hidden="true"></span></a> 
					<a target="_blank" href="/enquiry/v_review.do?path=${enquiry.excelpath}">预览</a>
					[#if enquiry.qtype?? &&  enquiry.qtype== 2 && (enquiry.state == EnqQuoteEnum.QUT_STAY.index)]
					<!--<button type="button" class="btn btn-xs btn-danger" onclick="purAnalysis('${enquiry.excelpath!}' , '${enquiry.excelName!}' , ${enquiry.id} , ${enquiry.projectId!} , ${enquiry.enquiryId!})">采析</button>-->
					[/#if]
					[#if enquiry.qtype?? &&  enquiry.qtype==1  && (enquiry.state == EnqQuoteEnum.QUT_STAY.index) ]
						<button type="button" class="btn btn-xs btn-danger" onclick="analysis(${enquiry.id})">解析</button>
                        <button type="button" class="btn btn-xs btn-info" onclick="uploaddialog(${enquiry.id!},'${enquiry.title!}','${enquiry.qtype!1}')">上传</button>
					[/#if]
					[#else]
						无
					[/#if]
				</td>
				
				<td style="/*max-width: 150px;*/">
					<!--[#if enquiry.qitem > 0]-->
						<button type="button" class="btn btn-xs btn-info" onclick="fullscreen(${enquiry.enquiryId!},${enquiry.id!})">详情</button>
					<!--[/#if]-->
					[#if (enquiry.state == EnqQuoteEnum.QUT_STAY.index) && enquiry.qitem > 0 ]
						<button type="button" class="btn  btn-xs  btn-success"  onclick="changeState(${enquiry.id!} , 1)">通过审核</button>
					[/#if ]
					[#if (!enquiry.suggest?? || enquiry.suggest == '') && enquiry.budget == 0]
						<button type="button" class="btn   btn-xs  btn-default" onclick="changeState(${enquiry.id!} , 3)" >退回修改</button>
					[/#if]
				 </td>
			</tr>
			[/#list]
		</table>

		<div class="panel-footer">[@fenye p = pagination form = 'infoForm' /]</div>
	</div>
</body>
</html>